package com.beone.admin.controller.app;

import com.base.common.beans.Result;
import com.beone.admin.common.UploadHelper;
import com.beone.admin.controller.app.common.BaseAppController;
import com.beone.admin.entity.Feedback;
import com.beone.admin.service.FeedbackService;
import com.beone.admin.service.VersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartHttpServletRequest;

/**
 * <p>
 * 系统相关
 * </p>
 *
 * @author Pagenny
 * @date 2019-05-24 19:21
 **/
@RestController
@Api(value = "系统相关",tags = {"APP端"})
@RequestMapping("/api/system")
public class SystemController extends BaseAppController {

    @Autowired
    private VersionService versionService;
    @Autowired
    private FeedbackService feedbackService;
    @Autowired
    private UploadHelper uploadHelper;

    /**
     * 获取系统时间戳
     * @return
     */
    @ApiOperation("获取系统时间戳")
    @GetMapping("/getTime")
    public Result getTime() {
        return Result.success("", String.valueOf(System.currentTimeMillis()));
    }

    /**
     * 获取最新版本信息
     * @return
     */
    @ApiOperation("获取最新版本信息")
    @GetMapping("/version")
    public Result version() {
        return Result.success(versionService.getLatestVersion());
    }

    /**
     * 新增用户反馈
     * @return
     */
    @ApiOperation("新增用户反馈")
    @PostMapping("/feedback")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "content", value = "反馈内容", required = true, paramType = "param", dataType = "string"),
            @ApiImplicitParam(name = "type", value = "反馈类型", required = true, paramType = "param", dataType = "string")
    })
    public Result feedback(String content,Integer type) {
        return Result.success(feedbackService.addFeedback(content, type, super.getUserId()));
    }

    /**
     * 上传
     * @param request
     * @return
     */
    @ApiOperation(value = "文件上传", notes = "fieldName 的值为文件列表的属性名称")
    @CrossOrigin
    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE
            , produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
        @ApiImplicitParam(name = "fieldName", value = "文件列表定义的名字", required = true, paramType = "param", dataType = "string"),
        @ApiImplicitParam(name = "accept", value = "分类（自定义如 image、video等）", required = false, paramType = "param", dataType = "string")
    })
    public Object upload(MultipartHttpServletRequest request){
        return uploadHelper.upload(request);
    }
}
